package model

import "github.com/hfdend/gosql"

type StaffCollectCity struct {
    base    `json:"-" field:"-"`

    Id       int   `field:"id"`
    StaffId  int   `field:"staff_id"`
    CityCode int   `field:"city_code"`
}

func NewStaffCollectCity() *StaffCollectCity {
    m := new(StaffCollectCity)
    m.init("staff_collect_city")
    return m
}

func (this *StaffCollectCity) GetStaffCity(staffId int) (list []*City, err error) {
    cond := this.DB.NewCondition()
    cond.SetFilter("staff_id", staffId)
    var res gosql.Values
    res, err = this.DB.SetCondition(cond).InnerJoin("city", "city.code = staff_collect_city.city_code").FindAll()
    if err != nil || res == nil {
        return
    }
    res.Scan(&list)
    return
}

func (this *StaffCollectCity) DelStaffCity(staffId, city_code int) error {
    cond := this.DB.NewCondition()
    cond.SetFilter("staff_id", staffId)
    cond.SetFilter("city_code", city_code)
    _, err := this.DB.SetCondition(cond).Del()
    return err
}
